home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 23 Character Animation / SkinnedMesh / LoadM3d.h < prev    next >
C/C++ Source or Header  |  2016-03-02  |  2KB  |  78 lines

  1. #ifndef LOADM3D_H
  2. #define LOADM3D_H
  3.  
  4. #include "SkinnedData.h"
  5.  
  6.  
  7.  
  8. class M3DLoader
  9. {
  10. public:
  11.     struct Vertex
  12.     {
  13.         DirectX::XMFLOAT3 Pos;
  14.         DirectX::XMFLOAT3 Normal;
  15.         DirectX::XMFLOAT2 TexC;
  16.         DirectX::XMFLOAT4 TangentU;
  17.     };
  18.  
  19.     struct SkinnedVertex
  20.     {
  21.         DirectX::XMFLOAT3 Pos;
  22.         DirectX::XMFLOAT3 Normal;
  23.         DirectX::XMFLOAT2 TexC;
  24.         DirectX::XMFLOAT3 TangentU;
  25.         DirectX::XMFLOAT3 BoneWeights;
  26.         BYTE BoneIndices[4];
  27.     };
  28.  
  29.     struct Subset
  30.     {
  31.         UINT Id = -1;
  32.         UINT VertexStart = 0;
  33.         UINT VertexCount = 0;
  34.         UINT FaceStart = 0;
  35.         UINT FaceCount = 0;
  36.     };
  37.  
  38.     struct M3dMaterial
  39.     {
  40.         std::string Name;
  41.  
  42.         DirectX::XMFLOAT4 DiffuseAlbedo = { 1.0f, 1.0f, 1.0f, 1.0f };
  43.         DirectX::XMFLOAT3 FresnelR0 = { 0.01f, 0.01f, 0.01f };
  44.         float Roughness = 0.8f;
  45.         bool AlphaClip = false;
  46.  
  47.         std::string MaterialTypeName;
  48.         std::string DiffuseMapName;
  49.         std::string NormalMapName;
  50.     };
  51.  
  52.     bool LoadM3d(const std::string& filename, 
  53.         std::vector<Vertex>& vertices,
  54.         std::vector<USHORT>& indices,
  55.         std::vector<Subset>& subsets,
  56.         std::vector<M3dMaterial>& mats);
  57.     bool LoadM3d(const std::string& filename, 
  58.         std::vector<SkinnedVertex>& vertices,
  59.         std::vector<USHORT>& indices,
  60.         std::vector<Subset>& subsets,
  61.         std::vector<M3dMaterial>& mats,
  62.         SkinnedData& skinInfo);
  63.  
  64. private:
  65.     void ReadMaterials(std::ifstream& fin, UINT numMaterials, std::vector<M3dMaterial>& mats);
  66.     void ReadSubsetTable(std::ifstream& fin, UINT numSubsets, std::vector<Subset>& subsets);
  67.     void ReadVertices(std::ifstream& fin, UINT numVertices, std::vector<Vertex>& vertices);
  68.     void ReadSkinnedVertices(std::ifstream& fin, UINT numVertices, std::vector<SkinnedVertex>& vertices);
  69.     void ReadTriangles(std::ifstream& fin, UINT numTriangles, std::vector<USHORT>& indices);
  70.     void ReadBoneOffsets(std::ifstream& fin, UINT numBones, std::vector<DirectX::XMFLOAT4X4>& boneOffsets);
  71.     void ReadBoneHierarchy(std::ifstream& fin, UINT numBones, std::vector<int>& boneIndexToParentIndex);
  72.     void ReadAnimationClips(std::ifstream& fin, UINT numBones, UINT numAnimationClips, std::unordered_map<std::string, AnimationClip>& animations);
  73.     void ReadBoneKeyframes(std::ifstream& fin, UINT numBones, BoneAnimation& boneAnimation);
  74. };
  75.  
  76.  
  77.  
  78. #endif // LOADM3D_H